package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tan.model.domain.User;
import com.tan.model.vo.HuanXinUserVo;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class Userapiimpl implements Userapi{
    @Autowired
    private UserMapper userMapper;
    @Override

    public User findByMobile(String mobile) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile", mobile); // 设置查询条件
        User user = userMapper.selectOne(queryWrapper); // 执行查询
        return user; // 返回查询结果
    }

    @Override
    public User save(User user) {
        this.userMapper.insert(user);
        return user;
    }


    @Override
    public void changePhone(String phone, Long userId) {
        User user = new User();
        user.setId(userId);
        user.setMobile(phone);
        this.userMapper.updateById(user);
    }

    @Override
    public void updateHxUser(String hxuser, Long id,String hxpassword) {
      User user = new User();
      user.setId(id);
      user.setHxUser(hxuser);
      user.setHxPassword(hxpassword);
      this.userMapper.updateById(user);
    }

    @Override
    public HuanXinUserVo searchUser(Long userId) {
      User user = this.userMapper.selectById(userId);
      if (user != null){
          return new HuanXinUserVo(user.getHxUser(),user.getHxPassword());
      }
        return null;
    }

    @Override
    public User searchUserInfo(String huanxinUserId) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("hx_user",huanxinUserId);
        User user = userMapper.selectOne(queryWrapper);

        return user;
    }

    @Override
    public User findById(Long valueOf) {
        User user = userMapper.selectById(valueOf);
        return user;
    }

    @Override
    public void update(User user) {
        this.userMapper.updateById(user);
    }
}
